#ifndef _H_BINARYTREE_DYNAMIC_LYVM_H_
#define _H_BINARYTREE_DYNAMIC_LYVM_H_

/*
	目前BinaryTree Dynamic layout 只針對 binary tree結構 , 不支援 2-3 tree或多個child的tree
*/
#include "Basic_Dynamic_lyvm.h"
#include "Animable.h"

using namespace std;

typedef std::map<int,std::vector<DIVA_VM*>> levelmap;
typedef std::map<DIVA_VM*,std::vector<pair<int,DIVA_VM*>>> linkmap;
//pair<int,DIVA_VM*> , int = 0 = left , int = 1 = right

class BinaryTree_Dynamic_Lyvm:public Basic_Dynamic_lyvm,Animable{
private:
	DIVA_VM* _root;
	levelmap _levels;
	linkmap _links;
	std::vector<pair<int,DIVA_VM*>> searchChildFromLink(DIVA_VM*);
	void determineChildsPosition(DIVA_VM*,std::vector<pair<int,DIVA_VM*>>,int);
	void arrangeChildsByLevel();
	void earseLinks();
	void constructLinks(DIVA_VM*);
	void insertPositionRecord(DIVA_VM*,Ogre::Vector3);
	void searchRoot(std::vector<DIVA_VM*>);
public:
	BinaryTree_Dynamic_Lyvm();
	void initial(DIVA_VM*);
	void setupParameters();
	void setupDialog();
	void showDialog(){};
	string getDescription(){return "This is a binary tree example layout.";}
	void layout(std::vector<DIVA_VM*>,DIVA_VM* = NULL);
	void behavior(float);
};
#endif